import 'package:flutter/material.dart';
import 'package:flutter_application_1/provider/counter_provider.dart';
import 'package:provider/provider.dart';

class CounterPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    final _counterProvider =
        Provider.of<CounterProvider>(context, listen: false);

    print('视图渲染');

    return Scaffold(
      appBar: AppBar(
        title: Text('计数器'),
      ),
      body: Center(
        child: Consumer<CounterProvider>(
          builder: (BuildContext context, CounterProvider _counterProvider,
              Widget? child) {
            print('局部刷新');

            return Text('${_counterProvider.count}');
          },
        ),
      ),
      floatingActionButton: FloatingActionButton(
        child: Icon(Icons.add),
        onPressed: () {
          _counterProvider.increment();
        },
      ),
    );
  }
}
